package com.wuhao.shootclient.handler;

import android.os.Handler;
import android.os.Message;

import com.wuhao.shootclient.MainActivity;

import java.lang.ref.WeakReference;

/**
 * Create by hao on 2019-11-14
 */
public class VoiceHandler extends Handler {
    private static final int msgWhat = 0x1001;
    private static final int refreshTime = 100;
    WeakReference<MainActivity> mActivity;
    private float mSound;

    VoiceHandler(MainActivity activity) {
        mActivity = new WeakReference<>(activity);
    }

    @Override
    public void handleMessage(Message msg) {
        MainActivity theActivity = mActivity.get();
        if (theActivity == null) {
            return;
        }
        if (this.hasMessages(msgWhat)) {
            return;
        }
        mSound = theActivity.mRecorder.getMaxAmplitude();  //获取声压值
        if (mSound > 0 && mSound < 1000000) {
            double v = Math.log10(mSound);
//            Log.e("====", "--对数--" + v + "--声压--" + mSound + "--处理分贝--" + VoiceTools.dbCount + "--真实分贝--" + 20 * (float) (Math.log10(mSound)));
            if (mSound >= 32767) {

            }
            // Log.e("====", "声音大于" + World.dbCount + "分贝" + size + "次" + "------" + volume);
               /* if (World.dbCount >= 85) {
                  //  size++;
                    mTextView.setText("声音大于" + World.dbCount + "分贝" + size + "次" + "------" + volume);
                }*/


        }
        this.sendEmptyMessageDelayed(msgWhat, refreshTime);
    }
}
